import RouterTable, { getRoutes } from "./router";
import { message } from "antd";
import { Suspense, useEffect, useRef } from "react";
import { useDispatch } from "react-redux";
import permissionToken from "./utils/permissionToken";
import { useLocation, useNavigate } from "react-router-dom";
import { getStorage, setStorage } from "./utils/utils";
import { TOKEN_NAME } from "./config";
import store from "./store";
function App() {
  message.config({
    top: 20,
    duration: 2,
    maxCount: 1,
    rtl: true,
    prefixCls: "my-message",
  });
  const dispatch = useDispatch();
  const navigate = useNavigate();

  useEffect(() => {
    permissionToken(dispatch);

    if (!getStorage(TOKEN_NAME)) {
      navigate("/login", { replace: true });
    }
  }, []);
  const routeArr = getRoutes();

  return (
    <Suspense>
      <RouterTable />
    </Suspense>
  );
}

export default App;
